package com.example.gorannet;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.Toast;
import android.widget.TabHost.TabSpec;

public class AppSettings extends Fragment {
	EditText t;
	MyChoices ob = new MyChoices();

	BootstrapButton reg, sql_btn,toggle;
    private EditText                      name, email, sql_edittext;

    private AlertDialogManager            alert           = new AlertDialogManager();
    
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.system_settings_layout,container, false);
		TabHost tabHost = (TabHost)view.findViewById(android.R.id.tabhost);
        tabHost.setup();
        gcm(tabHost);
        
        sql_edittext = (EditText)view.findViewById(R.id.sql_edittext);
        sql_btn = (BootstrapButton)view.findViewById(R.id.set_btn);
        sql_btn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(getActivity(), sql_edittext.getText(), Toast.LENGTH_LONG).show();
			}
		});
        
        name = (EditText)view.findViewById(R.id.subj);
        email = (EditText)view.findViewById(R.id.txtEmail);
        reg = (BootstrapButton)view.findViewById(R.id.btnRegister);
        reg.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				String name1 = name.getText().toString();
	            String email1 = email.getText().toString();

	            // Check if user filled the form
	            if (name1.trim().length() > 0 && email1.trim().length() > 0)
	            {
	                // Launch Main Activity
	                Intent i = new Intent(getActivity(), MainActivity.class);

	                // Registering user on our server
	                // Sending registration details to MainActivity
	                i.putExtra("name", name1);
	                i.putExtra("email", email1);
	                startActivity(i);

	                // finish();
	            }
	            else
	            {
	                // user doen't filled that data
	                // ask him to fill the form
	                alert.showAlertDialog(getActivity(), "Registration Error!",
	                        "Please enter your details", false);
	            }
			}
		});
        return view;
	}
	
	
	public void gcm(TabHost tabHost)
	{
		
		TabSpec ts = tabHost.newTabSpec("tag1"); 
		ts.setContent(R.id.tab1);
	    ts.setIndicator("GCM");
	    tabHost.addTab(ts);
	    
	    ts = tabHost.newTabSpec("tag2"); 
	    ts.setContent(R.id.tab2);
	    ts.setIndicator("SQL");  
	    tabHost.addTab(ts);

	  
	}
}